import { IpcMain, dialog } from 'electron/main'

export function ipcCommon(ipcMain: IpcMain): void {
  ipcMain.handle('open:dialog', async (_event, options: Electron.OpenDialogOptions) => {
    const { canceled, filePaths } = await dialog.showOpenDialog(options)

    if (canceled) {
      throw canceled
    } else {
      return filePaths[0]
    }
  })
}
